<?php
/**
 * @author Voislav Jovanovic <voislavj@gmail.com>
 * main entry point for the framework
 */

error_reporting(E_ERROR); ini_set("display_errors", "On");

define("DEFAULT_CONTROLLER",	"Page");
define("DEFAULT_ACTION",		"index");

$sysdir = str_replace("\\", "/",dirname(__FILE__));
define("DIR_ROOT",				substr($sysdir, 0, strrpos($sysdir, "/")+1));

function __autoload($className) {

	$base = str_replace("\\", "/", dirname(__FILE__)) . "/../";

	$fileName = class2file($className);
	$locations = array(
		"app/controllers/" => "%s.php",
		"app/models/" => "%s.php",
		"sys/" => "%s.class.php"
	);
	
	$found = false;
	foreach($locations as $path=>$mask) {
		$p = $base . $path . sprintf($mask, $fileName);
		if(file_exists($p)) {
			$found = true;
			require_once $p;
			break;
		}
	}
	
	if(!$found) {
		throw new Exception("Class not found ($className).");
	}
}

?>